/*
 * @(#)posix_jit_profil.h	1.7 06/10/10
 *
 * Copyright  1990-2008 Sun Microsystems, Inc. All Rights Reserved.  
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER  
 *   
 * This program is free software; you can redistribute it and/or  
 * modify it under the terms of the GNU General Public License version  
 * 2 only, as published by the Free Software Foundation.   
 *   
 * This program is distributed in the hope that it will be useful, but  
 * WITHOUT ANY WARRANTY; without even the implied warranty of  
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  
 * General Public License version 2 for more details (a copy is  
 * included at /legal/license.txt).   
 *   
 * You should have received a copy of the GNU General Public License  
 * version 2 along with this work; if not, write to the Free Software  
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  
 * 02110-1301 USA   
 *   
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa  
 * Clara, CA 95054 or visit www.sun.com if you need additional  
 * information or have any questions. 
 *
 */

#ifndef _POSIX_JIT_PROFIL_H
#define _POSIX_JIT_PROFIL_H

/*
 * Define jit profiling api's based on the posix profil() function.
 *
 * CVMJIT_PROFILE_REGION_SIZE must be defined before including this file.
 */

#include <unistd.h>

#define CVMJIT_PROFILE_SCALING_FACTOR \
    (CVMJIT_PROFILE_REGION_SIZE / sizeof(u_short))

#ifndef CVMJITprofileBufferSize
#define CVMJITprofileBufferSize() \
    (jgs->codeCacheSize / CVMJIT_PROFILE_SCALING_FACTOR)
#endif

extern int
CVMJITprofil(u_short *buf, size_t bufsiz, size_t offset, u_int scale);

#ifndef CVMJITprofileEnable
#define CVMJITprofileEnable()                                \
    CVMJITprofil(jgs->profileBuf, CVMJITprofileBufferSize(), \
	   (size_t)CVMglobals.jit.codeCacheStart,            \
	   65536 / CVMJIT_PROFILE_SCALING_FACTOR);
#endif

#ifndef CVMJITprofileEnable
#define CVMJITprofileEnable() \
    profil(NULL, 0, 0, 0);
#endif

#ifndef CVMJITprofileGetNextProfiledRegion
#define CVMJITprofileGetNextProfiledRegion(regionPtr) \
    ((regionPtr) + CVMJIT_PROFILE_REGION_SIZE)
#endif

#ifndef CVMJITprofileGetSampleCount
#define CVMJITprofileGetSampleCount(regionPtr)				     \
    (CVMglobals.jit.profileBuf[(regionPtr - CVMglobals.jit.codeCacheStart) / \
			      CVMJIT_PROFILE_REGION_SIZE])
#endif

#ifndef CVMJIT_PROFILE_SAMPLES_PER_SECOND
#define CVMJIT_PROFILE_SAMPLES_PER_SECOND 100
#endif

#endif /* _POSIX_JIT_PROFIL_H */
